import 'package:flutter/material.dart';
import 'package:hello_flutter/pages/tabs2/DetailPage.dart';

class TestFabTab extends StatefulWidget {
  @override
  _TestFabTabState createState() => _TestFabTabState();
}

class _TestFabTabState extends State<TestFabTab> {
  List<Widget> _eachView = [];
  int _index = 0;

  @override
  void initState() {
    super.initState();
    _eachView.addAll([
      DetailPage("Home", "Home page"),
      DetailPage("My", "My page"),
    ]);
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: _eachView[_index],
      floatingActionButton: new FloatingActionButton(
        child: new Icon(Icons.add),
        tooltip: 'Create',
        onPressed: () {
          Navigator.of(context).push(
            MaterialPageRoute(
              builder: (BuildContext context) {
                return DetailPage("New", "Create page");
              },
            ),
          );
        },
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
      bottomNavigationBar: BottomAppBar(
        color: Colors.blue,
        shape: CircularNotchedRectangle(),
        child: Container(
          height: 50.0,
          child: Row(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            children: <Widget>[
              FlatButton.icon(
                label: Text(
                  "首页",
                  style: TextStyle(color: Colors.white),
                ),
                icon: Icon(Icons.home, color: Colors.white),
                color: Colors.transparent,
                onPressed: () {
                  setState(() {
                    _index = 0;
                  });
                },
              ),
              FlatButton.icon(
                label: Text(
                  "我的",
                  style: TextStyle(color: Colors.white),
                ),
                icon: Icon(Icons.person, color: Colors.white),
                color: Colors.transparent,
                onPressed: () {
                  setState(() {
                    _index = 1;
                  });
                },
              ),
            ],
          ),
        ),
      ),
    );
  }
}
